igraph
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(igraph)
##
## Attaching package: 'igraph'
## The following object is masked from 'package:plotly':
##
## groups
## The following objects are masked from 'package:stats':
##
## decompose, spectrum
## The following object is masked from 'package:base':
##
## union
library(ggnetwork)
g <- read.table("/Users/daniel/Downloads/small_higgs.edgelist")
g <- graph_from_data_frame(g,directed=T,vertices=NULL)
tiny_g <- induced_subgraph(g,1:10)
plot(tiny_g)

gn <- ggnetwork(tiny_g)
g <- ggplot(gn,aes(x=x,y=y,xend=xend,yend=yend)) + geom_nodes() + geom_edges()
g

gn_1 <- ggnetwork(tiny_g,layout=as_tree())
g <- ggplot(gn_1,aes(x=x,y=y,xend=xend,yend=yend)) + geom_nodes() + geom_edges()
g

L <- layout_as_tree(tiny_g)
rownames(L) <- V(tiny_g)$name
el <- as_edgelist(tiny_g)
edge_to_shape <- function(the_row){
v0 <- the_row[1]
v1 <- the_row[2]
the_shape <- list(
type="line",
line=list(color="gray",width=0.3),
x0 = L[v0,1],
y0 = L[v0,2],
x1 = L[v1,1],
y1 = L[v1,2]
)
}
the_edges <- apply(el,1,edge_to_shape)
edges <- data.frame(ax=L[el[,1],1])
edges$ay <- L[el[,1],2]
edges$x <- L[el[,2],1]
edges$y <- L[el[,2],2]
fig <- plot_ly(x=L[,1],y=L[,2],text=V(tiny_g)$name)
fig <- fig %>% add_markers()
#fig <- fig %>% layout(shapes=the_edges)
fig <- fig %>% add_annotations(data=edges,
x=~x,
y=~y,
ax=~ax,
ay=~ay,
text="",
xref = "x", yref = "y",
axref = "x", ayref = "y",
showarrow=T)
fig